package network.byteConversions;
import tools.Point;
public class ByteArrayWriter {
	private byte data[];
	private ByteMapper bmapper;
	public ByteArrayWriter(ByteMapper bmap) {
		bmapper = bmap;
		data = new byte[bmapper.getTotalSize()];
	}
	public void writeFloat(String vname, Float f) {
		int offs = bmapper.getOffset(vname);
		byte fdata[] = ByteConverter.floatToBytes(f);
		data[offs] = fdata[0];
		data[offs + 1] = fdata[1];
		data[offs + 2] = fdata[2];
		data[offs + 3] = fdata[3];
	}
	public void writeInt(String vname, int i) {
		int offs = bmapper.getOffset(vname);
		byte idata[] = ByteConverter.intToBytes(i);
		data[offs] = idata[0];
		data[offs + 1] = idata[1];
		data[offs + 2] = idata[2];
		data[offs + 3] = idata[3];
	}
	public void writeChar(String vname, char c) {
		int offs = bmapper.getOffset(vname);
		data[offs] = ByteConverter.charToByte(c);
	}
	public void writeBoolean(String vname, boolean b) {
		int offs = bmapper.getOffset(vname);
		data[offs] = ByteConverter.booleanToByte(b);
	}
	public void writePoint(String vname, Point p) {
		int offs = bmapper.getOffset(vname);
		byte pd[] = ByteConverter.pointToBytes(p);
		for (int i = 0; i < 8; i++) {
			data[offs + i] = pd[i];
		}
	}
	public byte[] getData() {
		return data;
	}
	public void writeLong(String vname, long l) {
		int offs = bmapper.getOffset(vname);
		byte lb[] = ByteConverter.longToBytes(l);
		for (int i = 0; i < 8; i++) {
			data[offs + i] = lb[i];
		}
	}
}
